package com.example.truthordare;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class QuestionAdapter extends BaseAdapter {
	private Context context;
	private static final String TAG = QuestionAdapter.class.getSimpleName();
	ArrayList<Question> listArray;

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listArray.size();
	}

	public QuestionAdapter(Context context, ArrayList<Question> listArray) {
		super();
		this.context = context;
		this.listArray = listArray;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (view == null) {
			LayoutInflater inflater = LayoutInflater.from(parent.getContext());
			view = inflater.inflate(R.layout.rowquestion, parent, false);
		}
		Log.i("question adapter", "view");
		final Question ques = listArray.get(position);
		TextView textView = (TextView) view.findViewById(R.id.rowsques);
		textView.setText(ques.Question);
		textView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Toast.makeText(context, "button clicked: " + ques.getId(),
						Toast.LENGTH_SHORT).show();
			}
		});
		return view;
	}
}
